export default {
    /**
     * 用户是否登录
     * @param activity_id
     * @param call
     */
    isLogin(activity_id,call){
        Axios.post(sysinfo.url,Qs.stringify({
            pages:'Admin',
            doing:'testLogin',
            activity_id:activity_id
        }))
            .then((res)=>{
                if(res.data.status == 'success'){
                    call(res.data.data);
                }else{
                    call(false);
                }
            })
            .catch(error=>console.log(error));
    },

    /**
     *验证活动状态
     */
    checkActivity(activity_id,call){
        if(activity_id){
            Axios.post(sysinfo.url,Qs.stringify({
                pages:'admin',
                doing:'checkActivity',
                activity_id:activity_id
            }))
                .then((res)=>{
                    if(res.data.status == 'success'){
                        call(true);
                    }else{
                        call(false);
                    }
                })
                .catch(error=>console.log(error));
        }else{
            call(false);
        }
    },

    /**
     *将一个数字转为金钱格式的数字
     * @param x
     * @returns {string|boolean}
     */
    toDecimal2(x){
        var f = parseFloat(x);
        if (isNaN(f)) {
            return false;
        }
        var f = Math.round(x*100)/100;
        var s = f.toString();
        var rs = s.indexOf('.');
        if (rs < 0) {
            rs = s.length;
            s += '.';
        }
        while (s.length <= rs + 2) {
            s += '0';
        }
        return s;
    },

    /**
     *将一个时间戳格式化为2019-11-11
     * @param time
     * @returns {string}
     */
    timeFormat(time){
        if(typeof time == 'number'){
            time = new Date(time);
        }
        var month = time.getMonth()+1;
        if(month < 10) month = '0'+ month;
        var date = time.getDate();
        if(date < 10) date = '0'+date;
        return time.getFullYear()+'-'+month+'-'+date;
    }
}